package com.smartstate.dataManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartstate.dataManagement.dto.PageDTO;
import com.smartstate.dataManagement.entity.LoginLog;
import com.smartstate.dataManagement.entity.Role;
import com.smartstate.dataManagement.eunm.CommonEunm;
import com.smartstate.dataManagement.mapper.LoginLogMapper;
import com.smartstate.dataManagement.service.LoginLogService;
import com.smartstate.dataManagement.util.StringUtils;
import com.smartstate.dataManagement.util.WrapperUtil;
import com.smartstate.dataManagement.vo.LoginLogVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
@Slf4j
public class LoginLogSericeImpl   extends ServiceImpl<LoginLogMapper, LoginLog> implements LoginLogService {

    @Autowired
    private LoginLogMapper loginLogMapper;

    @Override
    public Page<LoginLog> getListByNameOrDept(PageDTO<LoginLog> pageDTO) {
        //创建查询语句包装器和分页查询表对象
        Page page = new Page(pageDTO.getPage(), pageDTO.getSize());
        //根据DTO注解封装查询语句
        LoginLog dto = (LoginLog) pageDTO.getDto();
        QueryWrapper<LoginLog> wrapper = WrapperUtil.convertQuery(dto, LoginLog.class);
        wrapper.orderByDesc(CommonEunm.LOGINTIME.getValue());
        if(null != dto){
            if(StringUtils.isNotBlank(dto.getNickname())){
                wrapper.like("NICKNAME",dto.getNickname());
            }
            if(StringUtils.isNotBlank(dto.getRoleName())){
                wrapper.eq("roleName",dto.getRoleName());
            }
        }
        //返回分页查询结果
        return baseMapper.selectPage(page,wrapper);
    }

    @Override
    public Boolean deleteLogByID(String id) {
        boolean result=false;
        if(loginLogMapper.deleteLogByID(id)>0){
            result=true;
        }
        return result;
    }

    @Override
    public Boolean batchDeleteByIDs(List<String> ids) {
        Boolean result=false;
        if(loginLogMapper.batchDelByIds(ids)>0){
            result=true;
        }
        return result;
    }


    @Override
    public Page<LoginLog> queryAllPageByDTO(PageDTO pageDTO) {
        return null;
    }
}
